﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
//
using System.Windows.Forms;
using Lib.CommonForm;
using System.Data;
using Lib.Common;

namespace AUI
{
    public static class modItems
    {
        public static void Menu_Init(ToolStripMenuItem menuItem)
        {
            ToolStripMenuItem itemMenu = null;
            List<ToolStripItem> arrItem = new List<ToolStripItem>();
            String menuName = "mnuItems_";
            //
            itemMenu = FormGlobals.Menu_NewItem(menuName + "Branch", "Đơn vị");
            Menu_InitItems(itemMenu);
            arrItem.Add(itemMenu);
            //
            FormGlobals.Menu_AddItem(arrItem, menuName + "Department", "Phòng ban");
            
            //----- ToolStripSeparator : Đường kẻ ngang -------
            //FormGlobals.Menu_AddItem(arrItem);
            //

            ////////////////////////////////////////////////////////////////////////////////////////////////
            foreach (ToolStripItem item in arrItem)
            {
                if (item is ToolStripMenuItem)
                {
                    (item as ToolStripMenuItem).DropDownItemClicked += Menu_DropDownItemClicked;
                }
            }
            menuItem.DropDownItems.Clear();
            menuItem.DropDownItems.AddRange(arrItem.ToArray());
            menuItem.DropDownItemClicked += Menu_DropDownItemClicked;

            FormGlobals.Menu_AutoShortcut(menuItem);
        }

        private static void Menu_InitItems(ToolStripMenuItem menuItem)
        {
            List<ToolStripItem> arrItem = new List<ToolStripItem>();
            //
            String menuName = menuItem.Name;
            switch (menuName)
            {
                //case "mnuItems_Branch":
                //    //
                //    FormGlobals.Menu_AddItem(arrItem, menuName + "_Storage", "Storage");
                //    //
                //    break;

            }
            menuItem.DropDownItems.AddRange(arrItem.ToArray());
        }

        public static void Menu_DropDownItemClicked(object sender, ToolStripItemClickedEventArgs e)
        {
            if (!FormGlobals.Menu_ShowForm(e.ClickedItem))
            {
                //manual show form here
                String menuName = e.ClickedItem.Name;
                string prefix = "mnu";
                if (menuName.StartsWith(prefix))
                    menuName = menuName.Substring(menuName.IndexOf(prefix) + prefix.Length);
                switch (menuName)
                {
                    case "mnuItems_Branch":
                        (new frmBranchList()).Show_Form();
                        break;
                    case "mnuItems_Department":
                        (new frmDepartmentList()).Show_Form();
                        break;
                }
            }
        }

    }
}